<?php
/**
 * 验证码控制器
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/1/6
 * Time: 11:24
 */

namespace App\Http\Controllers\MiniProgram;


use App\Http\Logics\MiniProgram\CaptchaLogic;
use App\Http\Traits\CaptchaTrait;
use App\Http\Controllers\BaseController;
class CaptchaController extends BaseController
{
    use CaptchaTrait;

    /**
     * @SWG\Post(
     *     path="/captcha/create",
     *     tags={"Captcha"},
     *     description="创建验证码",
     *     operationId="createCaptcha",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="mobile",
     *         in="query",
     *         description="手机号",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function createCaptcha()
    {
        $loginSession = $this->loginSession;
        $mobile = $this->mobile;
        $data = [
            'loginSession' => $loginSession,
            'mobile' => $mobile
        ];
        $response = CaptchaLogic::createCaptcha($data);
        if ($response->code){
            return self::response($response->code, $response->message);
        }
        return self::response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Post(
     *     path="/captcha/verify",
     *     tags={"Captcha"},
     *     description="校验验证码,验证码过期(6001),验证码错误(6002)",
     *     operationId="verifyCaptcha",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="mobile",
     *         in="query",
     *         description="手机号",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="captcha",
     *         in="query",
     *         description="验证码",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function verifyCaptcha()
    {
        $loginSession = $this->loginSession;
        $mobile = $this->mobile;
        $captcha = $this->captcha;
        $data = [
            'loginSession' => $loginSession,
            'mobile' => $mobile,
            'captcha' => $captcha
        ];
        $response = CaptchaLogic::verifyCaptcha($data);
        if ($response->code){
            return self::response($response->code, $response->message);
        }
        return self::response($response->code, $response->message, $response->data);
    }
}